package com.baomidou.mybatisplus.samples.quickstart.chain;

import com.baomidou.mybatisplus.samples.quickstart.entity.ApiUrlParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;

/**
 * 跳转URL参数处理责任链
 */
@Component
public class UrlParamsHandlerChain {

    @Autowired
    private List<UrlParamsHandler> handlers;

    public String handle(ApiUrlParam apiUrlParam) {
        String url = apiUrlParam.getUrl();
        if (StringUtils.isBlank(url)) {
            return url;
        }
        for (UrlParamsHandler handler : handlers) {
            url = handler.handle(apiUrlParam);
            apiUrlParam.setUrl(url);
        }
        return url;
    }
}
